package com.sdry.web.controller.llm;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.hpf.StationStatus;
import com.sdry.service.llm.ProductionReportService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * 生产报表
 * @Title:ProductionReportController
 * @Package com.sdry.web.controller.llm
 * @author llm
 * @date 2018年12月24日
 * @version 1.0
 */

@Controller
@RequestMapping(value="/productionReport")
public class ProductionReportController {

	@Resource
	private ProductionReportService productionReportService;
	
	/**
	 * 当天当班生产报表
	 * @Title:listAllProductionStatusByTimeAndTeam   
	 * @param time 日期
	 * @param teamName 班组名称
	 * @param response 
	 * @throws Exception
	 */
	@RequestMapping(value="/listAllProductionStatusByTimeAndTeam")
	public void listAllProductionStatusByTimeAndTeam(String time, String teamName, HttpServletResponse response)throws Exception{
		Map<String, Object> map = new HashMap<>();
		if(null != time && !"".equals(time)){
			map.put("time", time);
		}else{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			map.put("time", date);
		}
		if(null != teamName && !"".equals(teamName)){
			map.put("teamName", teamName);
		}else{
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
			String date = sdf.format(new Date());
			Integer teamTime = Integer.parseInt(date.substring(0, 2));
			if(teamTime >= 8 && teamTime <= 20){
				map.put("teamName", "白班");
			}else{  
				map.put("teamName", "晚班");
			}
		}
		List<StationStatus> stationStatusList = productionReportService.listAllProductionStatusByTimeAndTeam(map);
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(stationStatusList, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);
		jsonObject.put("count", 0);
		ResponseUtil.write(response, jsonObject);
	}
	
}
